/* 
 * File:   ProcessManager.h
 * Author: bharat
 *
 * Created on October 4, 2009, 10:44 AM
 */

#ifndef _PROCESSMANAGER_H
#define	_PROCESSMANAGER_H

#include "P2Defs.h"

#include "thread.h"
#include "syscall.h"
#include "table.h"
#include "Process.h"

class ProcessManager {
public:
    ProcessManager(); 
    //createNewThread: Create a new process.
    // Arguments:   the prog name to be executed.
    // Returns:     The new spaceID.
    // Chage: SpaceId is nothing but the process Index. Each procees has a point
    SpaceId Exec(char *);

    //createNewThread: Create a new thread.
    // Arguments:   the function pointer to which it needs to point to.
    // Returns:     The new thread's id.

    int createNewThread(unsigned int functionPtr);

    //Exit:         Delete a thread.
    // Arguments:   The exit code.
    // Returns:     Nothing.
    void Exit(int exitCode);


    //getThread: Retrieve one thread.
    // Arguments:   The id of the thread to retrieve.
    // Returns:     A thread
    //
    Process* getProcess(int pid);

    // handlers for lock reletead sys calls
    int createLock() ;
    int destroyLock(int) ;
    int acquireLock(int) ;
    int releaseLock(int) ;

    //handelers for Condition related sys calls
    int createCondition() ;
    int destroyCondition(int) ;
    int signalOnCondition(int ,int) ;
    int waitOnCondition(int,int) ;
    int broadCastOnCondition(int,int) ;

private: 
    int noOfProcess ;   //keeps track of how many processes are running. (CAUTION: Max 100 process are allowed to run at a time :D )
    Table processTable; // The process TABLE. Maintains all the processes.
    Lock* pmLock ;
}; /* class ProcessManager */


#endif	/* _PROCESSMANAGER_H */

